/**
 * Copyright (C)  2011 Kent Tong <freemant2000@yahoo.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.ttdev.ecofoods;

import java.util.Locale;

import android.database.Cursor;

public class FoodColumns {
	private int idColIdx;
	private int nameColIdx;
	private int scientificNamesColIdx;
	private int descColIdx;
	private int originColIdx;
	private int cultColIdx;
	private int recommendKeyColIdx;

	public FoodColumns(LocalesService ls, Cursor c) {
		idColIdx = c.getColumnIndex("_id");
		nameColIdx = getColumnIndexForName(ls, c);
		scientificNamesColIdx = getColumnIndexForScientificNames(ls, c);
		descColIdx = getColumnIndexForDesc(ls, c);
		originColIdx = c.getColumnIndex("origin");
		cultColIdx = c.getColumnIndex("cult");
		recommendKeyColIdx = c.getColumnIndex("recommendation");
	}

	private int getColumnIndexForName(LocalesService ls, Cursor c) {
		return getIndexForLocalizedColumn(ls, c, "name");
	}

	private int getColumnIndexForDesc(LocalesService ls, Cursor c) {
		return getIndexForLocalizedColumn(ls, c, "desc");
	}

	private int getColumnIndexForScientificNames(LocalesService ls, Cursor c) {
		return getIndexForLocalizedColumn(ls, c, "scientific_names");
	}

	private int getIndexForLocalizedColumn(LocalesService ls, Cursor c,
			String colBaseName) {
		Locale bestLocale = ls.getBestLocale();
		return c.getColumnIndex(colBaseName + "_" + bestLocale.toString());
	}

	public int getIdColIdx() {
		return idColIdx;
	}

	public int getNameColIdx() {
		return nameColIdx;
	}

	public int getDescColIdx() {
		return descColIdx;
	}

	public int getOriginColIdx() {
		return originColIdx;
	}

	public int getCultColIdx() {
		return cultColIdx;
	}

	public int getRecommendKeyColIdx() {
		return recommendKeyColIdx;
	}

	public int getscientificNamesColIdx() {
		return scientificNamesColIdx;
	}

}
